package com.hmall.user.web;

import com.hmall.common.ThreadLocalUtil;
import com.hmall.user.pojo.Address;
import com.hmall.user.pojo.User;
import com.hmall.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequestMapping("address")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/address/uid")
    public List<Address> findAddressByUserId() {
        Long userId = ThreadLocalUtil.getUserId();
        return userService.findAddressByUserId(userId);
    }

    @GetMapping("/address/{addressId}")
    public Address findAddressByAddressId(@PathVariable("addressId") String addressId){
        return userService.findAddressByAddressId(addressId);
    }

    @GetMapping("/user/{id}")
    public User findUserByUserId(@PathVariable("id")Long userId){
//        Long userId = ThreadLocalUtil.getUserId();
        System.out.println("用户id:" +userId);
        return userService.findUserByUserId(userId);
    }

    @RequestMapping("user/{totalFee}")
    public void updateBalance(@PathVariable("totalFee") Long totalFee){
        userService.updateBalance(totalFee);
    }

}
